package com.itchu.customer;

import com.itchu.system.domain.Comment;
import com.itchu.system.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/api/comment")
public class vCommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 添加评论
     * @param comment
     * @return
     */
    @RequestMapping("/save")
    public ResponseEntity<Map<String,Integer>> saveComent(Comment comment) {

        Map<String ,Integer> map = new HashMap<>();

        Integer i = commentService.saveComent(comment);

        map.put("code",i);

        return ResponseEntity.ok(map);
    }

    /**
     * 查询歌单的评论
     * @param songlistId
     * @return
     */
    @RequestMapping("/songListComments")
    public ResponseEntity<List<Comment>> getSongListComments(
            @RequestParam(value = "songlistId") Long songlistId
    ) {

        List<Comment> list = commentService.getSongListComments(songlistId);
        return ResponseEntity.ok(list);
    }

    /**
     * 查询歌单的评论
     * @param songId
     * @return
     */
    @GetMapping("/songComments")
    public ResponseEntity<List<Comment>> getSongComments(
            @RequestParam(value = "songId") Long songId
    ) {
        List<Comment> list = commentService.getSongComments(songId);
        return ResponseEntity.ok(list);
    }
}
